{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Simulating Probabilities [demonstration]\n",
    "The code below shows one method for simulating dice rolls. Read through it and try to understand how it works. \n",
    "\n",
    "**What does the data stored in `roll_counts` represent?**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 came up 197 times\n",
      "2 came up 162 times\n",
      "3 came up 162 times\n",
      "4 came up 152 times\n",
      "5 came up 164 times\n",
      "6 came up 163 times\n"
     ]
    }
   ],
   "source": [
    "import random as rd\n",
    "\n",
    "def simulate_dice_rolls(N):\n",
    "    roll_counts = [0,0,0,0,0,0]\n",
    "    for i in range(N):\n",
    "        roll = rd.choice([1,2,3,4,5,6])\n",
    "        index = roll - 1\n",
    "        roll_counts[index] = roll_counts[index] + 1\n",
    "    return roll_counts\n",
    "\n",
    "def show_roll_data(roll_counts):\n",
    "    number_of_sides_on_die = len(roll_counts)\n",
    "    for i in range(number_of_sides_on_die):\n",
    "        number_of_rolls = roll_counts[i]\n",
    "        number_on_die = i+1\n",
    "        print(number_on_die, \"came up\", number_of_rolls, \"times\")\n",
    "        \n",
    "roll_data = simulate_dice_rolls(1000)\n",
    "show_roll_data(roll_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Basic Data Visualization [optional]\n",
    "This section is optional but you may find it interesting.\n",
    "\n",
    "You'll learn more about this throughout the Nanodegree, but  now is a great time to look at one data visualization tool called a histogram."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEWCAYAAABrDZDcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vb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dMDvK8f2fKXdM9a2BG4fRbr3Bt4\nKnBBnx2bALdNMt8BwH/oX38c+J8TPvtsVf0SuCbJjnPYn8nC6kV0g8+9tX+/ObA73TMkpHkxCLQx\n+CxwQpJnAI8Zf9gOcAQwBuxXVff1I3huvs6y9/PQlvH45wGurqq5PnJw4km3f5nwerYtkb2AB+ie\npfDkdZZ/RVVdP8d6pBnZNaRFr38i2UV03TdnTfhoG7qx/O9L8nxgj0kWvwnYJ8mjk2xDN3IkwPXA\n2PizZ5NsmuQpkyz/LbpWCHTBc/Ej3Y8kY8D/Bk6uh1/F8WXgDeNdW0n2faTbkdZli0Abi7OAc/nV\nH2Xo+uw/3z8c/QomGY66qm5OcjZwJXADcHk//Rf9Cd6T+oBYQveksKvXWcUbgdOTvI3uKVVzHXXy\nMf3Ir5vStU4+Dkw2JPif9tu/sg+D1XTnHqR58/JRSWqcXUOS1DiDQJIaZxBIUuMMAklqnEEgSY0z\nCCSpcQaBJDXu/wOdHydaSRzyvgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc8202a3898>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "\n",
    "def visualize_one_die(roll_data):\n",
    "    roll_outcomes = [1,2,3,4,5,6]\n",
    "    fig, ax = plt.subplots()\n",
    "    ax.bar(roll_outcomes, roll_data)\n",
    "    ax.set_xlabel(\"Value on Die\")\n",
    "    ax.set_ylabel(\"# rolls\")\n",
    "    ax.set_title(\"Simulated Counts of Rolls\")\n",
    "    plt.show()\n",
    "    \n",
    "roll_data = simulate_dice_rolls(500)\n",
    "visualize_one_die(roll_data)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
